<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<%@ include file="../../common/tag.jsp"%>
<!DOCTYPE html>
<HTML>
<HEAD>
	<TITLE>菜单树-选择</TITLE>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" href="../../resource/css/demo.css" type="text/css">
	<link rel="stylesheet" href="../../resource/css/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="../../resource/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="../../resource/js/jquery.ztree.core-3.2.js"></script>
	<script type="text/javascript" src="../../resource/js/jquery.ztree.excheck-3.2.js"></script>
	<SCRIPT type="text/javascript">
		<!--
		var setting = {
			view: {
				selectedMulti: false
			},
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onCheck: onCheck
			}
		};

		function onCheck(e, treeId, treeNode) {
			count();
		}
		function count() {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			var array=zTree.getCheckedNodes(true);
			var id="";
			var name="";
 			for(var i=0;i<array.length;i++){
 				id+=array[i].id+",";
 				name+=array[i].name+",";
			}
			$("#checkedMenuId").val(id);
			$("#checkedMenuName").val(name);
 		}
		
		//取得菜单树
		$(document).ready(function(){
			var roleId=$("#roleId").val();
			$.ajax({
				url:"../../menu/showTreeCheckBox.action?roleId="+roleId,
				type:"GET",
				cache:false,
				async:false,
				error:function(json){
					 alert('Error loading XML document');
			         return false;
				},
				success:function(json){
					$.fn.zTree.init($("#treeDemo"), setting, eval(json.menuTree));
				}
			});
			count();
		});
		
		//提交后关闭页面
		function submitAndClose(){
			var roleId=$("#roleId").val();
			var checkedMenuId=$("#checkedMenuId").val();
			$.ajax({
				url:"../../menu/assignPower.action?checkedMenuId="+checkedMenuId+"&roleId="+roleId,
				type:"GET",
				cache:false,
				async:false,
				error:function(json){
					 alert('Error loading XML document');
			         return false;
				},
				success:function(json){
					if(json.state){
						window.close();
					}
				}
			});
		}
		//-->
	</SCRIPT>
</HEAD>
<%
	String roleId=String.valueOf(request.getParameter("roleId"));
%>
<BODY>
<form method="post" action="">
	<input type="hidden" id="checkedMenuId" name="checkedMenuId"/>
	<input type="hidden" id="roleId" name="roleId" value="<%=roleId%>"/>
	<ul id="treeDemo" class="ztree"></ul>
	<input type="button" onclick="return submitAndClose();" value="确定"/>
</form>
</BODY>
</HTML>